package com.cn.kabalifeuser.ui.service.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.content.res.TypedArrayUtils;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.IBaseActivity;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.callback.SchedulerTransformer;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.event.RxBus;
import com.cn.kabalifeuser.event.RxBusBean;
import com.cn.kabalifeuser.ui.integral.adapter.CommodityParamsAdapter;
import com.cn.kabalifeuser.ui.my.activity.IAddressListActivity;
import com.cn.kabalifeuser.ui.my.adapter.GridImageAdapter;
import com.cn.kabalifeuser.ui.my.bean.MyUserInfoBean;
import com.cn.kabalifeuser.ui.my.bean.NumBean;
import com.cn.kabalifeuser.ui.my.bean.UpImgBean;
import com.cn.kabalifeuser.ui.release.FragmentReleasePresenter;
import com.cn.kabalifeuser.ui.release.FragmentReleaseView;
import com.cn.kabalifeuser.ui.release.activity.DepositPayActivity;
import com.cn.kabalifeuser.ui.release.activity.ReleaseListActivity;
import com.cn.kabalifeuser.ui.release.bean.AddSreviceBean;
import com.cn.kabalifeuser.ui.release.bean.JsonBean;
import com.cn.kabalifeuser.ui.release.bean.NumListBean;
import com.cn.kabalifeuser.ui.release.bean.ServiceInfoListBean;
import com.cn.kabalifeuser.ui.service.adapter.StrListAdapter;
import com.cn.kabalifeuser.ui.service.adapter.StrListAdapter2;
import com.cn.kabalifeuser.ui.service.bean.BannerListBean;
import com.cn.kabalifeuser.ui.service.bean.BusinessTypeBean;
import com.cn.kabalifeuser.ui.service.bean.StrListBean;
import com.cn.kabalifeuser.utils.GlideEngine;
import com.cn.kabalifeuser.utils.GlideUtil;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.cn.kabalifeuser.utils.RxToast;
import com.cn.kabalifeuser.utils.StringUtil;
import com.cn.kabalifeuser.utils.TimeUtils;
import com.cn.kabalifeuser.view.PopupWindow.CommonPopupWindow;
import com.cn.kabalifeuser.view.PopupWindow.CommonUtil;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.PostRequest;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
import rx.functions.Action1;

/**
 * Created by 晓林 on 2020/9/18.
 * function: 商家发布服务。
 */
public class ServiceAddActivity extends IBaseActivity<FragmentReleaseView, FragmentReleasePresenter> implements FragmentReleaseView {

    @BindView(R.id.tv_btn_address)
    TextView tvBtnAddress;
    @BindView(R.id.tv_address_name)
    TextView tvAddressName;
    @BindView(R.id.tv_address_phone)
    TextView tvAddressPhone;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.ll_btn_address)
    LinearLayout llBtnAddress;
    @BindView(R.id.tv_service)
    TextView tvService;
    @BindView(R.id.et_money)
    EditText etMoney;
    @BindView(R.id.et_fuwu_1)
    TextView etFuWu1;
    @BindView(R.id.et_fuwu_2)
    EditText etFuWu2;
    @BindView(R.id.tv_time_start)
    TextView tvTimeStart;
    @BindView(R.id.tv_time_end)
    TextView tvTimeEnd;
    int ids = 0;//返回的服务类型id
    public final static int onActivityResult_To_ComName = 1010;
    public static final int onActivityResult_To_Address = 110;
    int addressId = 0;
    //时间
    TimePickerView pvTime;
    int timeSign = 1;

    @BindView(R.id.recyclerviewpic)
    RecyclerView recyclerviewpic;
    private List<LocalMedia> selectList = new ArrayList<>();
    private int maxSelectNum = 3;
    private GridImageAdapter adapter;
    private int themeId;

    List<String> temListPicUrl = new ArrayList<>();//临时保存图片的地址，要比对上传过的是否存在。
    List<String> strPics = new ArrayList<>();
    List<String> list = new ArrayList<>();
    List<String> listIds = new ArrayList<>();


    List<StrListBean> typeList1 = new ArrayList<>();
    List<StrListBean.SubsetBean> typeList2 = new ArrayList<>();
    Bundle bundle;
    int id;
    private CommonPopupWindow popupWindowList;

    OptionsPickerView optionsPickerViewTyope; //
    private ArrayList<NumBean> itemTypeOptions = new ArrayList<>();


    //2lian
    OptionsPickerView optionsPickerViewWork;
    private List<JsonBean> options1Items = new ArrayList<>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();

    @Override
    protected FragmentReleasePresenter createPresenter() {
        return new FragmentReleasePresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_service_add;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        bundle = getIntent().getExtras();
        id = bundle.getInt("id");

        themeId = R.style.picture_default_style;
        recyclerviewpic.setLayoutManager(new GridLayoutManager(getMe(), 3));
        adapter = new GridImageAdapter(getMe(), onAddPicClickListener, 3);
        adapter.setList(selectList);
        adapter.setSelectMax(maxSelectNum);
        recyclerviewpic.setAdapter(adapter);
        adapter.setOnItemClickListener(new GridImageAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, View v) {
                if (selectList.size() > 0) {
                    LocalMedia media = selectList.get(position);
//                    LoggerUtils.e("这是：" + media.getPath() + media.getCompressPath() + media.getCutPath());
                    String mimeType = media.getMimeType();
                    int mediaType = PictureMimeType.getMimeType(mimeType);
                    switch (mediaType) {
                        case PictureConfig.TYPE_VIDEO:
                            // 预览视频
                            PictureSelector.create(ServiceAddActivity.this).externalPictureVideo(media.getPath());
                            break;
                        case PictureConfig.TYPE_AUDIO:
                            // 预览音频
                            PictureSelector.create(ServiceAddActivity.this).externalPictureAudio(media.getPath());
                            break;
                        default:
                            // 预览图片 可自定长按保存路径
//                        PictureWindowAnimationStyle animationStyle = new PictureWindowAnimationStyle();
//                        animationStyle.activityPreviewEnterAnimation = R.anim.picture_anim_up_in;
//                        animationStyle.activityPreviewExitAnimation = R.anim.picture_anim_down_out;
                            PictureSelector.create(ServiceAddActivity.this)
                                    .themeStyle(R.style.picture_default_style) // xml设置主题
                                    //.setPictureStyle(mPictureParameterStyle)// 动态自定义相册主题
                                    //.setPictureWindowAnimationStyle(animationStyle)// 自定义页面启动动画
                                    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)// 设置相册Activity方向，不设置默认使用系统
                                    .isNotPreviewDownload(false)// 预览图片长按是否可以下载
                                    .loadImageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
                                    .openExternalPreview(position, selectList);
                            break;
                    }
                }
            }
        });
        rxBusSubscription = RxBus.getDefault().toObservable(RxBusBean.class)
                .compose(new SchedulerTransformer<RxBusBean>())
                .subscribe(new Action1<RxBusBean>() {
                    @SuppressLint("WrongConstant")
                    @Override
                    public void call(RxBusBean rxBusBean) {
                        if (rxBusBean.getId() == 204 && rxBusBean.getSign() == 204) {
                            // 删除图片后才传值
                            int index = (int) rxBusBean.getObjBean();
//                            LoggerUtils.e("删除了图片收到之前集合：" + strPics.size() + "str：" + strPics.toString());
//                            LoggerUtils.e("删除了图片收到：" + index);
                            temListPicUrl.remove(index);// 删除临时集合里面的
//                            RxToast.success("这边注释掉一行代码,删除记得释放");
                            strPics.remove(index); // 删除要上传id集合里面的
//                            LoggerUtils.e("删除了图片收到之后集合：" + strPics.size() + "str：" + strPics.toString());

                        }
                    }
                });

    }

    private GridImageAdapter.onAddPicClickListener onAddPicClickListener = new GridImageAdapter.onAddPicClickListener() {
        @Override
        public void onAddPicClick() {
            // 进入相册 以下是例子：不需要的api可以不写
            PictureSelector.create(ServiceAddActivity.this)
                    .openGallery(PictureMimeType.ofImage())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                    .loadImageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
                    .theme(themeId)// 主题样式设置 具体参考 values/styles   用法：R.style.picture.white.style v2.3.3后 建议使用setPictureStyle()动态方式
                    .isWeChatStyle(false)// 是否开启微信图片选择风格
//                        .setLanguage(language)// 设置语言，默认中文
//                        .setPictureStyle(mPictureParameterStyle)// 动态自定义相册主题
//                        .setPictureCropStyle(mCropParameterStyle)// 动态自定义裁剪主题
//                        .setPictureWindowAnimationStyle(windowAnimationStyle)// 自定义相册启动退出动画
                    .isWithVideoImage(true)// 图片和视频是否可以同选,只在ofAll模式下有效
                    .maxSelectNum(maxSelectNum)// 最大图片选择数量
                    .minSelectNum(1)// 最小选择数量
                    //.maxVideoSelectNum(1) // 视频最大选择数量，如果没有单独设置的需求则可以不设置，同用maxSelectNum字段
                    //.minVideoSelectNum(1)// 视频最小选择数量，如果没有单独设置的需求则可以不设置，同用minSelectNum字段
                    .imageSpanCount(3)// 每行显示个数
                    .isReturnEmpty(false)// 未选择数据时点击按钮是否可以返回
                    //.isAndroidQTransform(false)// 是否需要处理Android Q 拷贝至应用沙盒的操作，只针对compress(false); && enableCrop(false);有效,默认处理
                    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)// 设置相册Activity方向，不设置默认使用系统
                    .isOriginalImageControl(false)// 是否显示原图控制按钮，如果设置为true则用户可以自由选择是否使用原图，压缩、裁剪功能将会失效
                    //.cameraFileName("test.png")    // 重命名拍照文件名、注意这个只在使用相机时可以使用，如果使用相机又开启了压缩或裁剪 需要配合压缩和裁剪文件名api
                    //.renameCompressFile("test.png")// 重命名压缩文件名、 注意这个不要重复，只适用于单张图压缩使用
                    //.renameCropFileName("test.png")// 重命名裁剪文件名、 注意这个不要重复，只适用于单张图裁剪使用
                    .selectionMode(
                            PictureConfig.MULTIPLE)// 多选 or 单选
                    .isSingleDirectReturn(false)// 单选模式下是否直接返回，PictureConfig.SINGLE模式下有效
                    .previewImage(true)// 是否可预览图片
                    .previewVideo(false)// 是否可预览视频
                    //.querySpecifiedFormatSuffix(PictureMimeType.ofJPEG())// 查询指定后缀格式资源
                    .enablePreviewAudio(false) // 是否可播放音频
                    .isCamera(true)// 是否显示拍照按钮
                    //.isMultipleSkipCrop(false)// 多图裁剪时是否支持跳过，默认支持
                    .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                    //.imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                    .enableCrop(false)// 是否裁剪
                    .compress(true)// 是否压缩
                    .compressQuality(80)// 图片压缩后输出质量 0~ 100
                    .synOrAsy(true)//同步false或异步true 压缩 默认同步
                    //.queryMaxFileSize(10)// 只查多少M以内的图片、视频、音频  单位M
                    //.compressSavePath(getPath())//压缩图片保存地址
                    //.sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效 注：已废弃
                    //.glideOverride(160, 160)// glide 加载宽高，越小图片列表越流畅，但会影响列表图片浏览的清晰度 注：已废弃
//                        .withAspectRatio(aspect_ratio_x, aspect_ratio_y)// 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
//                        .hideBottomControls(cb_hide.isChecked() ? false : true)// 是否显示uCrop工具栏，默认不显示
                    .isGif(false)// 是否显示gif图片
//                        .freeStyleCropEnabled(cb_styleCrop.isChecked())// 裁剪框是否可拖拽
//                        .circleDimmedLayer(cb_crop_circular.isChecked())// 是否圆形裁剪
                    //.setCircleDimmedColor(ContextCompat.getColor(this, R.color.app_color_white))// 设置圆形裁剪背景色值
                    //.setCircleDimmedBorderColor(ContextCompat.getColor(getApplicationContext(), R.color.app_color_white))// 设置圆形裁剪边框色值
                    //.setCircleStrokeWidth(3)// 设置圆形裁剪边框粗细
//                        .showCropFrame(cb_showCropFrame.isChecked())// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
//                        .showCropGrid(cb_showCropGrid.isChecked())// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
                    .openClickSound(true)// 是否开启点击声音
                    .selectionMedia(selectList)// 是否传入已选图片
                    //.isDragFrame(false)// 是否可拖动裁剪框(固定)
//                        .videoMaxSecond(15)
//                        .videoMinSecond(10)
                    //.previewEggs(false)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中)
                    //.cropCompressQuality(90)// 注：已废弃 改用cutOutQuality()
                    .cutOutQuality(90)// 裁剪输出质量 默认100
                    .minimumCompressSize(100)// 小于100kb的图片不压缩
                    //.cropWH()// 裁剪宽高比，设置如果大于图片本身宽高则无效
                    //.rotateEnabled(true) // 裁剪是否可旋转图片
                    //.scaleEnabled(true)// 裁剪是否可放大缩小图片
                    //.videoQuality()// 视频录制质量 0 or 1
                    //.videoSecond()//显示多少秒以内的视频or音频也可适用
                    //.recordVideoSecond()//录制视频秒数 默认60s
                    //.setOutputCameraPath("/CustomPath")// 自定义拍照保存路径  注：已废弃
                    .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
        }

    };

    @OnClick({R.id.ll_btn_left, R.id.tv_btn_list, R.id.ll_btn_service, R.id.ll_btn_time_start, R.id.ll_btn_time_end, R.id.ll_btn_add, R.id.ll_btn_conent,R.id.tv_btn_address,R.id.ll_btn_address})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_btn_address:
                Intent intent = new Intent(getMe(), IAddressListActivity.class);
                intent.putExtra("sign", onActivityResult_To_Address);
                startActivityForResult(intent, onActivityResult_To_Address);
                break;
            case R.id.ll_btn_address:
                intent = new Intent(getMe(), IAddressListActivity.class);
                intent.putExtra("sign", onActivityResult_To_Address);
                startActivityForResult(intent, onActivityResult_To_Address);
                break;
            case R.id.ll_btn_left:
                hideKeyboard(etFuWu2);
                finish();
                break;
            case R.id.tv_btn_list:
                $startActivity(ReleaseListActivity.class);
                break;
            case R.id.ll_btn_service:
//                Intent intent = new Intent(getMe(), CooperationSreviceActivity.class);
//                intent.putExtra("ids", String.valueOf(ids));
//                intent.putExtra("sign", 2);
//                startActivityForResult(intent, onActivityResult_To_ComName);
                if (optionsPickerViewTyope != null) {
                    optionsPickerViewTyope.show();
                } else {
                    mPresenter.onTypeData(id);
                }
                break;
            case R.id.ll_btn_time_start:
                timeSign = 1;
                if (pvTime != null) {
                    pvTime.show();
                } else {

                    showTimeSelector();
                    pvTime.show();
                }
                break;
            case R.id.ll_btn_time_end:
                timeSign = 2;
                if (pvTime != null) {
                    pvTime.show();
                } else {
                    showTimeSelector();
                    pvTime.show();
                }
                break;
            case R.id.ll_btn_conent:
                //todo 选择服务
                if (ids > 0)
                    mPresenter.onServiceInfoData(ids, id);
                else RxToast.error("请先选择服务类型");
                break;
            case R.id.ll_btn_add:
                if (ids > 0) {
                    if (!TextUtils.isEmpty(etMoney.getText().toString().trim())) {
                        if (!TextUtils.isEmpty(tvTimeStart.getText().toString().trim())) {
                            if (!TextUtils.isEmpty(tvTimeEnd.getText().toString().trim())) {
//                                    mPresenter.onAddSreviceData(LoginHelper.getLonginData().getResult(),
//                                            ids, etMoney.getText().toString().trim(),
//                                            etContent.getText().toString().trim(),
//                                            tvTimeStart.getText().toString().toString().trim() + "/" + tvTimeEnd.getText().toString().toString().trim());
                                if (!TextUtils.isEmpty(etFuWu1.getText().toString().trim()) || !TextUtils.isEmpty(etFuWu2.getText().toString().trim()) || listIds.size() > 0) {
                                   if (addressId >0) {
                                       String con = "";
                                       if (!TextUtils.isEmpty(etFuWu1.getText().toString().trim()) && !TextUtils.isEmpty(etFuWu2.getText().toString().trim()))
                                           con = etFuWu1.getText().toString().trim() + "-" + etFuWu2.getText().toString().trim();
                                       else if (TextUtils.isEmpty(etFuWu2.getText().toString().trim()))
                                           con = etFuWu1.getText().toString().trim() + "-";
                                       else if (TextUtils.isEmpty(etFuWu1.getText().toString().trim()))
                                           con = "-" + etFuWu2.getText().toString().trim();
                                       mPresenter.onAddSreviceData(LoginHelper.getLonginData().getResult(),
                                               ids, etMoney.getText().toString().trim(),
                                               con,
                                               tvTimeStart.getText().toString().trim() + "/" + tvTimeEnd.getText().toString().trim(), listIds, String.valueOf(id) ,addressId);
                                   }else RxToast.error("请选择地址");
                                } else RxToast.error("请选择服务类型或输入服务内容");

                            } else RxToast.error("请选择服务的结束时间");
                        } else RxToast.error("请选择服务的开始时间");
                    } else RxToast.error("请输入服务预算");
                } else RxToast.error("请选择服务类型");
                break;
        }
    }

    /**
     * 选择时间
     */
    private void showTimeSelector() {
        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        //startDate.set(2013,1,1);
        Calendar endDate = Calendar.getInstance();
        //endDate.set(2020,1,1);
        //正确设置方式 原因：注意事项有说明
        startDate.set(2000, 1, 1);
        endDate.set(2230, 11, 28);
        pvTime = new TimePickerBuilder(getMe(), new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                if (timeSign == 1)
                    tvTimeStart.setText(StringUtil.getTimeNYSFFormat(String.valueOf(date.getTime())));
                else
                {
                    int in= TimeUtils.timeCompare(tvTimeStart.getText().toString().trim(),StringUtil.getTimeNYSFFormat(String.valueOf(date.getTime())));
                    LoggerUtils.e("duibi:"+in);
                    if (in==3){
                        tvTimeEnd.setText(StringUtil.getTimeNYSFFormat(String.valueOf(date.getTime())));
                    }else RxToast.error("结束时间必须大于开始时间");
                }
            }
        })
                .setType(new boolean[]{true, true, true, true, true, true})
                .setSubmitText(getResources().getString(R.string.main_sure))
                .setCancelText(getResources().getString(R.string.main_cancel))
                .isCyclic(true)
                .setSubmitColor(getResources().getColor(R.color.main_color))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.font_black))//取消按钮文字颜色
                .setTitleBgColor(getResources().getColor(R.color.main_white))
                .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(startDate, endDate)//起始终止年月日设定
                .setLabel(getResources().getString(R.string.time_year_str), getResources().getString(R.string.time_month_str), getResources().getString(R.string.time_day_str), getResources().getString(R.string.time_hours_str), getResources().getString(R.string.time_mins_str), getResources().getString(R.string.time_second_str))//默认设置为年月日时分秒
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .isDialog(false).build();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case onActivityResult_To_Address:
                //上门返回来的地址。
                if (data != null) {
                    addressId = data.getIntExtra("addressId", 0);
                    String addressName = data.getStringExtra("addressName");
                    String address = data.getStringExtra("address");
                    String addressPhone = data.getStringExtra("addressPhone");
                    if (!TextUtils.isEmpty(addressName) && addressId > 0) {
                        tvBtnAddress.setVisibility(View.GONE);
                        llBtnAddress.setVisibility(View.VISIBLE);
                    } else {
                        tvBtnAddress.setVisibility(View.VISIBLE);
                        llBtnAddress.setVisibility(View.GONE);
                    }
                    tvAddressName.setText(addressName);
                    tvAddressPhone.setText(addressPhone);
                    tvAddress.setText(address);
                }
                break;
            case onActivityResult_To_ComName:
                if (data != null) {
                    String names = data.getStringExtra("names");
                    ids = data.getIntExtra("ids", 0);
                    tvService.setText(names);
                    LoggerUtils.e("选择的id返回来：" + ids);

                }
                break;
            case RESULT_OK:
                switch (requestCode) {
                    case PictureConfig.CHOOSE_REQUEST:
                        LoggerUtils.e("返回回調：");
                        // 图片选择结果回调
                        List<LocalMedia> result = data.getParcelableArrayListExtra(PictureConfig.EXTRA_RESULT_SELECTION);
                        for (LocalMedia b : result) {
                            LoggerUtils.e("返回：" + b.getPath());
                        }
                        selectList = PictureSelector.obtainMultipleResult(data);
                        // 例如 LocalMedia 里面返回五种path
                        // 1.media.getPath(); 为原图path
                        // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true
                        // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true
                        // 4.media.getOriginalPath()); media.isOriginal());为true时此字段才有值
                        // 5.media.getAndroidQToPath();为Android Q版本特有返回的字段，此字段有值就用来做上传使用
                        // 如果同时开启裁剪和压缩，则取压缩路径为准因为是先裁剪后压缩
                        adapter.setList(selectList);
                        adapter.notifyDataSetChanged();
                        if (temListPicUrl.size() > 0) {
                            for (LocalMedia media : selectList) {
                                Log.i("压缩:", media.getCompressPath());
                                if (temListPicUrl.contains(media.getCompressPath())) {
                                    //如果存在 不管
                                } else {
                                    //如果不存在的话就添加和上传上传
                                    temListPicUrl.add(media.getCompressPath());
                                    mPresenter.onUpImgData(media.getCompressPath());
                                }
                            }
                        } else {
                            for (int i = 0; i < selectList.size(); i++) {
                                temListPicUrl.add(selectList.get(i).getCompressPath());
//                                LoggerUtils.e("上传的图片：" +i+"地址："+ selectList.get(i).getCompressPath());
//                                mPresenter.onUpImgData(selectList.get(i).getCompressPath());
                                list.add(selectList.get(i).getCompressPath());

                            }
                            upAdFile();
                        }
                        break;

                }
                break;
        }
    }

    private void upAdFile() {
        if (list.size() > 0) {
            String time = TimeUtils.getTime10();
            PostRequest postRequest = OkGo.<UpImgBean>post(Api.API_UP_IMG);
            postRequest.params("type", "head");
            postRequest.params("file[]", new File(list.get(0)));
            postRequest.execute(new CacheCallBack<UpImgBean>() {
                @Override
                public void onSuccess(Response<UpImgBean> response) {
                    super.onSuccess(response);
                    UpImgBean bean = response.body();
                    if (bean.getCode() == Constants.HTTP_SUCCESS) {
                        strPics.add(bean.getMsg() + "/" + bean.getResult().get(0));
                        listIds.add(bean.getResult().get(0));
//                        LoggerUtils.e("图片的id：" + bean.getData().getId() + "图片的链接;" + bean.getData().getOriginal());
                        list.remove(0);
                        upAdFile();
                    } else if (bean.getCode() == Constants.HTTP_AGAIN_LOGIN) {
                        onReLoggedIn(response.body().getMsg());
                    } else {
                        RxToast.error(bean.getMsg());
                        list.remove(0);
                        upAdFile();
                    }

                }
            });
        }
    }

    /**
     * 类型
     */
    private void UserType() {
        optionsPickerViewTyope = new OptionsPickerBuilder(getMe(), new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx1 = itemTypeOptions.get(options1).getPickerViewText();
                tvService.setText(tx1);
                ids = itemTypeOptions.get(options1).getId();
            }
        }).setLayoutRes(R.layout.pw_store, new CustomListener() {
            @Override
            public void customLayout(View v) {
                TextView iv_cancel = v.findViewById(R.id.tv_cancel);
                TextView tvSubmit = v.findViewById(R.id.tv_next);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        optionsPickerViewTyope.returnData();
                        optionsPickerViewTyope.dismiss();
                    }
                });

                iv_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        optionsPickerViewTyope.dismiss();
                    }
                });
            }
        }).isDialog(false).build();
        optionsPickerViewTyope.setPicker(itemTypeOptions);//添加数据
    }

    @Override
    public void onReLoggedIn(String msg) {

        RxToast.error(msg);
        LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {
        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return getMe();
    }

    @Override
    public void onBannerSuccess(BannerListBean bean) {

    }

    @Override
    public void onUpImgSuccess(UpImgBean bean) {
        listIds.add(bean.getResult().get(0));
    }

    @Override
    public void onUserInfoSuccess(MyUserInfoBean bean) {

    }

    @Override
    public void onAddSreviceSuccess(AddSreviceBean bean) {
        List<String> mListStr = new ArrayList<>();
        for (int i = 0; i < bean.getResult().getService_type().size(); i++) {
            mListStr.add(bean.getResult().getService_type().get(i).getTitle());
        }
        RxToast.success(bean.getMsg());
        Bundle bundle = new Bundle();
        bundle.putInt("sign", 1);
        bundle.putInt("getService_id", bean.getResult().getService_id());
        bundle.putInt("getBusiness_id", bean.getResult().getBusiness_id());
        bundle.putString("getBus_title", bean.getResult().getBus_title());
        bundle.putString("getBus_cover", bean.getResult().getBus_cover());
        bundle.putString("getBus_fraction", bean.getResult().getBus_fraction());
        bundle.putString("getAddress_info", bean.getResult().getAddress_info());
        bundle.putStringArrayList("mListStr", (ArrayList<String>) mListStr);
        bundle.putString("getDeposit", bean.getResult().getDeposit());
        $startActivityFinish(DepositPayActivity.class, bundle);
    }

    @Override
    public void onServiceInfoSuccess(ServiceInfoListBean bean) {
        //TODO 服务类型内容
        options1Items.clear();
        options2Items.clear();
        if (bean.getResult() != null && bean.getResult().getService_info().size() > 0) {
            for (int i = 0; i < bean.getResult().getService_info().size(); i++) {
                JsonBean jsonBean = new JsonBean();
                jsonBean.setName(bean.getResult().getService_info().get(i).getName());
                List<JsonBean.CityBean> list = new ArrayList<>();
                for (int j = 0; j < bean.getResult().getService_info().get(i).getIs_val().size(); j++) {
                    list.add(new JsonBean.CityBean(bean.getResult().getService_info().get(i).getName(), bean.getResult().getService_info().get(i).getIs_val()));
                }
                jsonBean.setCityList(list);
                options1Items.add(jsonBean);

                ArrayList<String> cityList = new ArrayList<>();//该省的城市列表（第二级）
                ArrayList<ArrayList<String>> province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）
                for (int j = 0; j < bean.getResult().getService_info().get(i).getIs_val().size(); j++) {
                    String cityName = bean.getResult().getService_info().get(i).getIs_val().get(j);
                    cityList.add(cityName);//添加城市
                    ArrayList<String> city_AreaList = new ArrayList<>();//该城市的所有地区列表
//                    city_AreaList.addAll("");
                    province_AreaList.add(city_AreaList);//添加该省所有地区数据
                }
                options2Items.add(cityList);
                options3Items.add(province_AreaList);
            }
            if (options1Items.size() > 0) {
                UserInfo();
                optionsPickerViewWork.show();
            }
        } else {
            RxToast.error("暂无数据");
        }
    }

    @Override
    public void onTypeSuccess(BusinessTypeBean bean) {
        for (int i = 0; i < bean.getResult().size(); i++) {
            itemTypeOptions.add(new NumBean(bean.getResult().get(i).getId(), bean.getResult().get(i).getTitle()));
        }
        UserType();
        optionsPickerViewTyope.show();
    }

    private void UserInfo() {
        optionsPickerViewWork = new OptionsPickerBuilder(getMe(), new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx1 = options1Items.get(options1).getName();
                String tx2 = options2Items.get(options1).get(options2);
                etFuWu1.setText(tx1 + "-" + tx2);
            }
        }).setLayoutRes(R.layout.pw_store, new CustomListener() {
            @Override
            public void customLayout(View v) {
                TextView iv_cancel = v.findViewById(R.id.tv_cancel);
                TextView tvSubmit = v.findViewById(R.id.tv_next);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        optionsPickerViewWork.returnData();
                        optionsPickerViewWork.dismiss();
                    }
                });

                iv_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        optionsPickerViewWork.dismiss();
                    }
                });
            }
        }).isDialog(false).build();
        optionsPickerViewWork.setPicker(options1Items, options2Items, null);//添加数据
    }


}
